<template >
    <div>
        <h1>当前求和{{sum}}</h1>
        <select v-model="n">
            <option :value="1">1</option>
            <option :value="2">2</option>
            <option :value="3">3</option>
        </select>
        <button @click="add">+</button>
        <button @click="sub">-</button>
        <button @click="addOdd">当前求和为奇数时再加</button>
        <button @click="addWait">等一等再加</button>
    </div>
</template>
<script>
export default {
    name:'Count',
    data() {
        return {
            n:1,
            sum:0
        }
    },
    methods: {
        
        add(){
            this.sum += this.n
        },
        sub(){
            this.sum -= this.n
        },
        addOdd(){
            if(this.sum%2 !== 0){
            this.sum += this.n
        }
        },
        addWait(){
            setTimeout(() => {
                this.sum += this.n
            }, 500);
        }
    },
    mounted(){
        console.log('@@@',this)
    }
}
</script>
<style lang="css">
    button{
        margin-left: 5px;
    }
</style>